package com.wc;

import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
public class Test {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StreamTokenizer st = new StreamTokenizer(br);
    static long nextLong() throws Exception {
        st.nextToken();
        return (long)st.nval;
    }
    static int nextInt() throws Exception {
        st.nextToken();
        return (int)st.nval;
    }

    static int n, q;
    static long[] a = new long[100010];
    static int[] Bl = new int[1000];
    static int[] Br = new int[1000];
    static int[] gid = new int[100010];
    static long[] flag = new long[1000];
    static ArrayList<Long>[] b = new ArrayList[1000];

    public static void main(String[] args) throws Exception {
        n = nextInt();
        for(int i = 1; i <= n; i++) {
            a[i] = nextLong();
        }
        int L = (int)Math.sqrt(n) + 1;
        int cnt = 0;
        for(int i = 1; i <= n; i += L) {
            cnt++;
            Bl[cnt] = i;
            Br[cnt] = Math.min(n, i + L - 1);
            b[cnt] = new ArrayList<Long>();
            for(int j = Bl[cnt]; j <= Br[cnt]; j++) {
                gid[j] = cnt;
                b[cnt].add(a[j]);
            }
            Collections.sort(b[cnt]);
        }
        q = nextInt();
        while(q-- > 0) {
            int opr = nextInt();
            int l = nextInt();
            int r = nextInt();
            long x = nextLong();
            int blid = gid[l];
            int brid = gid[r];
            if(opr == 1) {
                if(blid == brid) {
                    b[blid].clear();
                    for(int i = l ; i <= r; i++) {
                        a[i] += x;
                    }
                    clearAndAdd(blid);
                }else {
                    for(int i = blid + 1; i < brid; i++) {
                        flag[i] += x;
                    }
                    for(int i = l; i <= Br[blid]; i++) {
                        a[i] += x;
                    }
                    clearAndAdd(blid);
                    for(int i = Bl[brid]; i <= r; i++) {
                        a[i] += x;
                    }
                    clearAndAdd(brid);
                }
            }else {
                int ans = 0;
                if(blid == brid) {
                    x -= flag[blid];
                    for(int i = l; i <= r; i++) {
                        if(a[i] < x) ans++;
                    }
                }else {
                    for(int i = blid + 1; i < brid; i++) {
                        ans += low(x - flag[i], b[i]);
                    }
                    long tmp = x - flag[blid];
                    for(int i = l; i <= Br[blid]; i++) {
                        if(a[i] < tmp) ans++;
                    }
                    tmp = x - flag[brid];
                    for(int i = Bl[brid]; i <= r; i++) {
                        if(a[i] < tmp) ans++;
                    }
                }
                System.out.println(ans);
            }
        }
    }

    private static int low(long x, ArrayList<Long> list) {
        if(list.get(list.size() - 1) < x) return list.size();
        if (list.get(0) >= x) return 0;
        int l = 0, r = list.size() - 1;
        while(l < r) {
            int mid = (l + r + 1) >> 1;
            if(list.get(mid) < x) {
                l = mid;
            }else {
                r = mid - 1;
            }
        }
        return l + 1;
    }

    private static void clearAndAdd(int bid) {
        b[bid].clear();
        for(int i = Bl[bid]; i <= Br[bid]; i++) {
            b[bid].add(a[i]);
        }
        Collections.sort(b[bid]);
    }
}